<?php  
namespace app\modules\m\controllers\common;
use \app\common\components\BaseWebController;
use app\common\services\UrlService;
class BaseController extends BaseWebController{
	//允许的路径
	private $url_map=[
		'/index.php/m/user/bind',
		
		'/index.php/m/default/img_captch',
		'/index.php/m/default/get_captcha',
	];
	public $current_user;
	public function __construct($id,$modules,array $config=[])
	{
		parent::__construct($id,$modules,$config);
		$this->layout="main";
	}
	public function beforeAction($action){
		//判断是否为允许的路径
		$url=\Yii::$app->request->getUrl();
		$pos=strpos($url,"?");
		if($pos){
			$url=substr($url,0,strpos($url,"?")-1 );
		}
		
		if(in_array($url,$this->url_map)){
			return true;
		}
		//不在则判断是否登录没有登录则去登录

		if( !$this->checkLogin() ){
			$url=UrlService::buildMUrl('/user/bind');
			return header("Location:http://cj.com/index.php/m/user/bind");
		 	
		}
		return true;

	}
	//存在返回true 不存在返回false
	public function checkLogin(){
		//如果为允许页面返回true
		
		$cookies = \Yii::$app->request->cookies;
        $member = $cookies->get('member');
        //如果member不存在则返回false
        if(!$member){
        	return false;
        }
           
        $this->current_user=$member->value;  
        return true;
	}
}
?>